package com.acwing.partition12;

import java.io.*;
import java.util.*;

/**
 * @author `RKC`
 * @date 2021/12/26 16:50
 */
public class AC1100抓住那头牛 {

    private static final int N = (int) (2e5 + 10);
    private static final int[] dis = new int[N];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        int start = Integer.parseInt(s[0]), end = Integer.parseInt(s[1]);
        writer.write(String.valueOf(bfs(start, end)));
        writer.flush();
    }

    private static int bfs(int start, int end) {
        Arrays.fill(dis, -1);
        LinkedList<Integer> queue = new LinkedList<>();
        queue.addLast(start);
        dis[start] = 0;
        while (!queue.isEmpty()) {
            int curr = queue.pollFirst();
            if (curr == end) return dis[curr];
            if (curr + 1 < N && dis[curr + 1] == -1) {
                queue.addLast(curr + 1);
                dis[curr + 1] = dis[curr] + 1;
            }
            if (curr - 1 >= 0 && dis[curr - 1] == -1) {
                queue.addLast(curr - 1);
                dis[curr - 1] = dis[curr] + 1;
            }
            if (curr * 2 < N && dis[curr * 2] == -1) {
                queue.addLast(curr * 2);
                dis[curr * 2] = dis[curr] + 1;
            }
        }
        return -1;
    }
}
